home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / files.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-10  |  9.0 KB  |  262 lines

  1. /* System-dependent definitions of various files, spool directories, etc */
  2. #include "global.h"
  3. #include "config.h"
  4. #include "files.h"
  5. #include "socket.h"
  6.  
  7. #ifdef    MSDOS
  8. char *Startup = "/autoexec.nos";        /* Initialization file */
  9. char *Userfile = "/ftpusers";            /* Authorized FTP users and passwords */
  10. char *Hostfile = "/nos.rc";             /* hosts and passwords */
  11. char *Maillog = "/spool/mail.log";        /* mail log */
  12. char *Mailspool = "/spool/mail";        /* Incoming mail */
  13. char *Mailqdir = "/spool/mqueue";        /* Outgoing mail spool */
  14. char *Mailqueue = "/spool/mqueue/*.wrk";    /* Outgoing mail work files */
  15. char *Routeqdir = "/spool/rqueue";        /* queue for router */
  16. char *Alias = "/alias";                    /* the alias file */
  17. char *Dfile = "/domain.txt";            /* Domain cache */
  18. char *Fdir = "/finger";                    /* Finger info directory */
  19. char *Mboxlog = "/spool/node.log";        /* MBox activity log */
  20. char *Arealist = "/spool/areas";        /* List of message areas */
  21. char *Helpdir = "/spool/help";            /* Mailbox help file directory */
  22. char *Rewritefile = "/spool/rewrite";    /* Address rewrite file */
  23. char *Signature = "/spool/signatur";    /* Mail signature file directory */
  24. char *Popusers = "/popusers";            /* POP user and password file */
  25. char *Axroutefile = "/axroute.dat";        /* AX25 routes */
  26. char *Axroutetmp = "/axroute.tmp";        /* AX25 temp routes */
  27. char *Arproutefile = "/arproute.dat";    /* ARP entries */
  28. char *Arproutetmp = "/arproute.tmp";    /* ARP temp entries */
  29. char *Iproutefile = "/iproute.dat";     /* IP route entries */
  30. char *Iproutetmp = "/iproute.tmp";        /* IP temp route */
  31. #ifdef NETROM
  32. char *Nrroutefile = "/nrroute.dat";        /* NET/ROM routes */
  33. #endif
  34. char *Forwardfile = "/spool/forward.bbs";    /* Mail forwarding file */
  35. char *Historyfile = "/spool/history";
  36. char *News    = "/spool/news";              /* Top of NeWs file system */
  37. char *Active  = "/spool/news/active";    /* Active article file */
  38. char *Pointer = "/spool/news/pointer";    /* */
  39. char *NInfo   = "/spool/news/xinfo";       /* */
  40. char *Nhelp   = "/spool/news/help";
  41. char *History = "/spool/news/history";
  42. char *Forward = "/spool/news/junk";
  43. char *Poll    = "/spool/news/poll";
  44. char *Convers = "/convers.cfg";
  45. char *Bbsfile = "/bbs.cfg";
  46. char Eol[] = "\r\n";
  47. #define    SEPARATOR    "/"
  48. #endif
  49.  
  50. #ifdef    UNIX
  51. char *Startup = "./startup.net";        /* Initialization file */
  52. char *Config = "./config.net";            /* Device configuration list */
  53. char *Userfile = "./ftpusers";
  54. char *Hostfile = "./nos.rc";
  55. char *Mailspool = "./mail";
  56. char *Maillog = "./mail.log";            /* mail log */
  57. char *Mailqdir = "./mqueue";
  58. char *Mailqueue = "./mqueue/*.wrk";
  59. char *Routeqdir = "./rqueue";            /* queue for router */
  60. char *Alias = "./alias";            /* the alias file */
  61. char *Dfile = "./domain.txt";            /* Domain cache */
  62. char *Fdir = "./finger";            /* Finger info directory */
  63. char *Arealist = "./areas";            /* List of message areas */
  64. char *Helpdir = "./help";            /* Mailbox help file directory */
  65. char *Rewritefile = "./rewrite";        /* Address rewrite file */
  66. char *Signature = "./signatur";            /* Mail signature file directory */
  67. char *Popusers = "./popusers";            /* POP user and password file */
  68. char *News = "./news";            /* News messages and NNTP data */
  69. char *Forwardfile = "./forward.bbs";        /* Mail forwarding file */
  70. char *Historyfile = "./history";
  71. char *Convers = "./convers.cfg";
  72. char Eol[] = "\n";
  73. #define    SEPARATOR    "/"
  74. #endif
  75.  
  76. #ifdef    AMIGA
  77. char *Startup = "TCPIP:net-startup";
  78. char *Config = "TCPIP:config.net";        /* Device configuration list */
  79. char *Hostfile = "TCPIP:nos.rc";
  80. char *Userfile = "TCPIP:ftpusers";
  81. char *Mailspool = "TCPIP:spool/mail";
  82. char *Maillog = "TCPIP:spool/mail.log";
  83. char *Mailqdir = "TCPIP:spool/mqueue";
  84. char *Mailqueue = "TCPIP:spool/mqueue/#?.wrk";
  85. char *Routeqdir = "TCPIP:spool/rqueue";        /* queue for router */
  86. char *Alias = "TCPIP:alias";            /* the alias file */
  87. char *Dfile = "TCPIP:domain.txt";        /* Domain cache */
  88. char *Fdir = "TCPIP:finger";            /* Finger info directory */
  89. char *Arealist = "TCPIP:spool/areas";        /* List of message areas */
  90. char *Helpdir = "TCPIP:spool/help";        /* Mailbox help file directory */
  91. char *Rewritefile = "TCPIP:spool/rewrite";    /* Address rewrite file */
  92. char *Signature = "TCPIP:spool/signatur";    /* Mail signature file directory */
  93. char *Popusers = "TCPIP:/popusers";        /* POP user and password file */
  94. char *News = "TCPIP:/spool/news";        /* News messages and NNTP data */
  95. char *Forwardfile = "TCPIP:spool/forward.bbs";    /* Mail forwarding file */
  96. char *Historyfile = "TCPIP:spool/history";
  97. char *Convers = "TCPIP:convers.cfg";
  98. char Eol[] = "\r\n";
  99. #define    SEPARATOR    "/"
  100. #endif
  101.  
  102. #ifdef    MAC
  103. char *Startup ="Mikes Hard Disk:net.start";
  104. char *Config = "Mikes Hard Disk:config.net";        /* Device configuration list */
  105. char *Hostfile = "Mikes Hard Disk:nos.rc";
  106. char *Userfile = "Mikes Hard Disk:ftpusers";
  107. char *Mailspool = "Mikes Hard Disk:spool:mail:";
  108. char *Maillog = "Mikes Hard Disk:spool:mail.log:";
  109. char *Mailqdir = "Mikes Hard Disk:spool:mqueue:";
  110. char *Mailqueue = "Mikes Hard Disk:spool:mqueue:*.wrk";
  111. char *Routeqdir = "Mikes Hard Disk:spool/rqueue:";    /* queue for router */
  112. char *Alias = "Mikes Hard Disk:alias";            /* the alias file */
  113. char *Dfile = "Mikes Hard Disk:domain:txt";        /* Domain cache */
  114. char *Fdir = "Mikes Hard Disk:finger";            /* Finger info directory */
  115. char *Arealist = "Mikes Hard Disk:spool/areas";        /* List of message areas */
  116. char *Helpdir = "Mikes Hard Disk:spool/help";        /* Mailbox help file directory */
  117. char *Rewritefile = "Mikes Hard Disk:spool/rewrite";    /* Address rewrite file */
  118. char *Signature = "Mikes Hard Disk:spool/signatur";    /* Mail signature file directory */
  119. char *Popusers = "Mikes Hard Disk:/popusers";        /* POP user and password file */
  120. char *News = "Mikes Hard Disk:/spool/news";        /* News messages and NNTP data */
  121. char *Forwardfile = "Mikes Hard Disk:spool/forward.bbs"; /* Mail forwarding file */
  122. char *Historyfile = "Mikes Hard Disk:spool/history";
  123. char *Convers = "Mikes Hard Disk:convers.cfg";
  124. char Eol[] = "\r";
  125. #define    SEPARATOR    ":"
  126. #endif
  127.  
  128. char fatal[] = "503 Fatal error %sFILE %s\n";
  129. static char *roott = NULLCHAR;
  130.  
  131. /* Concatenate root, separator and arg strings into a malloc'ed output
  132.  * buffer, then remove repeated occurrences of the separator char
  133.  */
  134. static char *
  135. strcatdup(a)
  136. char *a;
  137. {
  138.     char *p1, *p2, *cp, *out = mxallocw(strlen(roott) + strlen(SEPARATOR) + strlen(a) + 2);
  139.  
  140. #ifdef MSDOS
  141.     while((cp = strchr(a,'\\')) != NULLCHAR)
  142.         *cp = '/';
  143. #endif
  144.  
  145.     strcpy(out,roott);
  146.     strcat(out,SEPARATOR);
  147.     strcat(out,a);
  148.     strcat(out,"\0");
  149.  
  150.     /* Remove any repeated occurrences of the separator char */
  151.     p1 = p2 = out;
  152.     while(*p2 != '\0'){
  153.         *p1++ = *p2++;
  154.         while(p2[0] == p2[-1] && p2[0] == roott[0])
  155.             p2++;
  156.     }
  157.     *p1 = '\0';
  158.  
  159.     return out;
  160. }
  161.  
  162. /* Establish a root directory other than the default. Can only be called
  163.  * once, at startup time
  164.  */
  165. void
  166. initroot(root)
  167. char *root;
  168. {
  169.     if(root != NULLCHAR)
  170.         roott = strxdup(root);
  171.  
  172.     Startup = strcatdup(Startup);
  173.     Userfile = strcatdup(Userfile);
  174.     Hostfile = strcatdup(Hostfile);
  175.     Maillog = strcatdup(Maillog);
  176.     Mailspool = strcatdup(Mailspool);
  177.     Mailqdir = strcatdup(Mailqdir);
  178.     Mailqueue = strcatdup(Mailqueue);
  179.     Routeqdir = strcatdup(Routeqdir);
  180.     Alias = strcatdup(Alias);
  181.     Dfile = strcatdup(Dfile);
  182.     Fdir = strcatdup(Fdir);
  183.     Arealist = strcatdup(Arealist);
  184.     Helpdir = strcatdup(Helpdir);
  185.     Rewritefile = strcatdup(Rewritefile);
  186.     Signature = strcatdup(Signature);
  187.     Popusers = strcatdup(Popusers);
  188.     Axroutefile = strcatdup(Axroutefile);
  189.     Axroutetmp = strcatdup(Axroutetmp);
  190.     Arproutefile = strcatdup(Arproutefile);
  191.     Arproutetmp = strcatdup(Arproutetmp);
  192.     Bbsfile = strcatdup(Bbsfile);
  193.     Iproutefile = strcatdup(Iproutefile);
  194.     Iproutetmp = strcatdup(Iproutetmp);
  195. #ifdef NETROM
  196.     Nrroutefile = strcatdup(Nrroutefile);
  197. #endif
  198.     Forwardfile = strcatdup(Forwardfile);
  199.     Historyfile = strcatdup(Historyfile);
  200.     News = strcatdup(News);
  201.     Mboxlog = strcatdup(Mboxlog);
  202.     Active = strcatdup(Active);
  203.     Pointer = strcatdup(Pointer);
  204.     NInfo = strcatdup(NInfo);
  205.     Nhelp = strcatdup(Nhelp);
  206.     History = strcatdup(History); 
  207.     Forward = strcatdup(Forward);
  208.     Poll = strcatdup(Poll);
  209.     Convers = strcatdup(Convers);
  210.     xfree(roott);
  211. }
  212.  
  213. /* main file-opening routine
  214.  * options: s = socketnumber, if given an error msg is printed to the socket
  215.  * returncode: NULLFILE if error; filepointer success
  216.  */
  217. FILE *
  218. open_file(name,mode,s,t)
  219. char *name;
  220. char *mode;
  221. int s;
  222. int t;
  223. {
  224.     FILE *f;
  225.     char *cp;
  226.  
  227.     if(name == NULLCHAR || mode == NULLCHAR)
  228.         return NULLFILE;
  229. #ifdef MSDOS
  230.     while((cp = strchr(name,'\\')) != NULLCHAR)
  231.         *cp = '/';
  232. #endif
  233.     if((f = fopen(name,mode)) == NULLFILE) {
  234.         if(s)
  235.             usprintf(s,fatal,"",name);
  236.         if(t)
  237.             tprintf("Can't open %s: %s\n",name,sys_errlist[errno]);
  238.     }
  239.     return f;
  240. }
  241.  
  242. /* main tempfile-opening routine
  243.  * returncode: NULLFILE if error; filepointer success
  244.  */
  245. FILE *
  246. temp_file(s,t)
  247. int s;
  248. int t;
  249. {
  250.     FILE *f;
  251.  
  252.     if((f = tmpfile()) == NULLFILE) {
  253.         if(s)
  254.             usprintf(s,fatal,"TMP","");
  255.         if(t) {
  256.             tprintf("Can't open TMP: %s\n",sys_errlist[errno]);
  257.         }
  258.     }
  259.     return f;
  260. }
  261.  
  262.